#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
int s[N];
int n;
string str;
map<int, int>mp;
int main()
{
	cin >> n;
	cin >> str;
	for (int i = 1; i <= n; i++) {
		if (str[i - 1] == '1') {
			s[i] = s[i - 1] + 1;
		}
		else {
			s[i] = s[i - 1] - 1;
		}
	}
	/*for (int i = 1; i <= n; i++) {
		cout << s[i] << " ";
	}
	cout << endl;*/
	if (s[n] == n || s[n] == -n) {
		cout << 0 << endl;
		return 0;
	}
	int ans = 0;
	mp[0] = 0;
	//1 2 3 4 5 4 3 2 1 0
	/*mp[1] = 1;
	mp[2] = 2;
	mp[3] = 3;
	mp[4] = 4;
	mp[5] = 5;*/
	// 1 1 1 1 1 0 0 0 0 0
	for (int i = 1; i <= n; i++) {
		if (mp.count(s[i])) {
			ans = max(ans, i - mp[s[i]]);
		}
		else {
			mp[s[i]] = i;
		}
	}
	/*for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			if (s[i] == s[j]) {
				ans = max(ans, i - j);
			}
		}
	}*/
	cout << ans << endl;
	return 0;
}